﻿using System;

namespace UniRx.Operators
{
	// Token: 0x02000258 RID: 600
	internal class CastObservable<TSource, TResult> : OperatorObservableBase<TResult>
	{
		// Token: 0x06000DC2 RID: 3522 RVA: 0x00041427 File Offset: 0x0003F827
		public CastObservable(IObservable<TSource> source) : base(source.IsRequiredSubscribeOnCurrentThread<TSource>())
		{
			this.source = source;
		}

		// Token: 0x06000DC3 RID: 3523 RVA: 0x0004143C File Offset: 0x0003F83C
		protected override IDisposable SubscribeCore(IObserver<TResult> observer, IDisposable cancel)
		{
			return this.source.Subscribe(new CastObservable<TSource, TResult>.Cast(observer, cancel));
		}

		// Token: 0x040007CE RID: 1998
		private readonly IObservable<TSource> source;

		// Token: 0x02000259 RID: 601
		private class Cast : OperatorObserverBase<TSource, TResult>
		{
			// Token: 0x06000DC4 RID: 3524 RVA: 0x00041450 File Offset: 0x0003F850
			public Cast(IObserver<TResult> observer, IDisposable cancel) : base(observer, cancel)
			{
			}

			// Token: 0x06000DC5 RID: 3525 RVA: 0x0004145C File Offset: 0x0003F85C
			public override void OnNext(TSource value)
			{
				TResult value2 = default(TResult);
				try
				{
					value2 = (TResult)((object)value);
				}
				catch (Exception error)
				{
					try
					{
						this.observer.OnError(error);
					}
					finally
					{
						base.Dispose();
					}
					return;
				}
				this.observer.OnNext(value2);
			}

			// Token: 0x06000DC6 RID: 3526 RVA: 0x000414D0 File Offset: 0x0003F8D0
			public override void OnError(Exception error)
			{
				try
				{
					this.observer.OnError(error);
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x06000DC7 RID: 3527 RVA: 0x00041508 File Offset: 0x0003F908
			public override void OnCompleted()
			{
				try
				{
					this.observer.OnCompleted();
				}
				finally
				{
					base.Dispose();
				}
			}
		}
	}
}
